home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 2002 January / PC Answers January 2002.7z / PC Answers January 2002.bin / graphics / freepixl / _SETUP.1 / Registry.pxl < prev    next >
Text File  |  1998-02-13  |  8KB  |  277 lines

  1. Initialize:
  2.     UseCoordinates(PIXEL)
  3.     UseBackGround(TRANSPARENT,192,192,192)
  4.     DrawBackGround
  5.     WaitInput(100)  {let NT and 95 catch up}
  6.     InfoMenu(REMOVE)
  7.     SetMenu()
  8.     Title$ = "Windows 95/NT Registry Commands"
  9.     UseCaption(Title$)
  10.     WinLocate(Title$,250,10,620,240,Res) 
  11.     WinShow(Title$,TOPMOST,Res)
  12.     DirGet(SourceDir$)
  13.  
  14.  
  15.     SetMenu("E&xit!",Leave,
  16.         ENDPOPUP,
  17.         "&Registry",IGNORE,
  18.         "&Open PiXCL4.1 Key",Open_Key,
  19.         "&Enum PiXCL4.1 Key",Enum_Key,
  20.         "&Close PiXCL4.1 Key",Close_Key,
  21.         SEPARATOR,
  22.         "&Add PiXCL4.1 Key",Create_Key,
  23.         "&Delete PiXCL4.1 Key",Delete_Key,
  24.         SEPARATOR,
  25.         "&Query PiXCL4.1 Key",QueryKey,
  26.         "&Query PiXCL4.1 Key Value",QueryValue,
  27.         ENDPOPUP,
  28.         "&Specific Tests",IGNORE,
  29.         "Get Ethernet Address",MAC_Address,
  30.         "Num To Hex",ToHex,
  31.         "Hex To Num", ToNum,
  32.         ENDPOPUP,
  33.         "&Help",IGNORE,
  34.         "&Information",Info,
  35.         "&View PXL source",ViewSource,
  36.         SEPARATOR,
  37.         "&About",About,
  38.         ENDPOPUP)
  39.     
  40. Wait_for_Input:
  41.     WaitInput()
  42.  
  43.  
  44. Leave:    {clean up after the demo}
  45.     RDBDeleteKey(@RDB_CLASSES_ROOT,"PiXCL4.1",Res)
  46.     End
  47.  
  48.  
  49. ToHex:
  50.     DrawBackground
  51.     Number = 29987665
  52.     DrawNumber(10,10,Number)
  53.     NumToHex(Number,HexNum$)
  54.     Drawtext(10,30,HexNum$)
  55.     Goto Wait_for_Input
  56.  
  57. ToNum:
  58.     DrawBackground
  59.     HexNum$ = "0287fdae"
  60.     HexToNum(HexNum$,Number,Res)
  61.     If Res = 1
  62.         DrawNumber(10,10,Number)
  63.         Drawtext(10,30,HexNum$)
  64.     Else
  65.         DrawText(10,10,"HexToNum failed.")
  66.     Endif
  67.     Goto Wait_for_Input
  68.  
  69. Info:
  70.     MessageBox(OK,1,INFORMATION,
  71. "This sample program shows you how to access the Registry.
  72. We suggest that you look at the PiXCL code first to see
  73. what is displayed as results in the client area. There are
  74. also comments in the PXL source that explain more fully
  75. what is happening.
  76.  
  77. To use this sample program, you must first create some
  78. entries in the Registry with the 'Create' menu item. Once
  79. entries are created, start up Windows REGEDIT and look in
  80. the HKEY_CLASSES_ROOT for the 'PiXCL4.1' entries.
  81.  
  82. The 'Open' menu item will now return success. Try the 
  83. 'Query' menu item and see that the information returned 
  84. is the same as you see with REGEDIT.
  85.  
  86. Please TAKE CARE accessing the Registry: trial and error 
  87. changes can result in a corrupted database, and a reload
  88. of all software may be necessary.",
  89.     "Using the Registry Access Sample program",Res)
  90.  
  91.     Goto Wait_for_Input
  92.  
  93.  
  94. ViewSource:
  95.     PXLfile$ = SourceDir$ + "\registry.pxl"
  96.     CmdLine$ = "Notepad " + PXLfile$
  97.     Run(CmdLine$)
  98.     Goto Wait_for_Input
  99.  
  100.  
  101. About:
  102.     AboutUser("PiXCL 4.1 Sample Program",
  103.           "Reading and Writing the Windows Registration Database.",
  104. "This sample program will create, read and delete 
  105. specific sample entries for PiXCL 4.1 in the Registry.
  106. No existing entries are accessed or changed.")
  107.     Goto Wait_for_Input
  108.  
  109. Open_Key:
  110.     DrawBackground
  111.     RDBOpenKey(@RDB_CLASSES_ROOT,"PiXCL4.1",Handle)
  112.     DrawNumber(10,10,Handle)
  113.     
  114.     Goto Wait_for_Input
  115.  
  116. QueryKey:
  117.     DrawBackground
  118.     RDBQueryKey(Handle,Class$, NumKeys, NumValues, Res)
  119.     If Class$ = "" Then Class$ = "Class$ returns NULL"
  120.     DrawText(10,10,Class$)
  121.     DrawNumber(10,30,NumKeys)
  122.     DrawNumber(10,50,NumValues)
  123.  
  124.     Goto Wait_for_Input
  125.  
  126.  
  127. QueryValue:
  128.     DrawBackground
  129.     RDBOpenKey(Handle,"DefaultIcon",IconHandle)
  130.     RDBOpenKey(Handle,"Image Formats",FMTHandle)
  131.     RDBOpenKey(Handle,"Properties",PtyHandle)
  132.  
  133.     RDBQueryValue(IconHandle,"",Value1$,Res) {gets "(Default)" value string}
  134.     RDBQueryValue(IconHandle,"SecondIcon",Value2$,Res) {gets specific value string}
  135.     RDBQueryValue(FMTHandle,"Type2",Value3$,Res) {gets specific value}
  136.  
  137.     RDBQueryValue(PtyHandle,"Type1",Value4$,Res) {gets specific value}
  138.  
  139.     DrawText(10,10,Value1$)
  140.     DrawText(10,35,Value2$)
  141.     DrawText(10,60,Value3$)
  142.     DrawText(10,85,Value4$)
  143.     Goto Wait_for_Input
  144.  
  145.  
  146. Close_Key:
  147.     DrawBackground
  148.     RDBCloseKey(Handle,Res)
  149.     DrawNumber(10,10,Res)
  150.     
  151.     Goto Wait_for_Input
  152.  
  153.  
  154. Create_Key:
  155.     DrawBackground
  156.     RDBCreateKey(@RDB_CLASSES_ROOT,"PiXCL4.1","",Handle,Res)
  157.     RDBCreateKey(Handle,"DefaultIcon","",PXL40IconHandle,Res)
  158.  
  159.     {In next, note NULL string, Handle defines location. This will add the 
  160.       value string to the "(Default)" Handle entry in the registry}
  161.  
  162.     RDBSetValue(PXL40IconHandle,"", "i:\p40tools\pdk\PiXCL41.exe,1",STRING,Res)
  163.  
  164.     RDBSetValue(PXL40IconHandle,"SecondIcon", {note new item in "DefaultIcon" tree}
  165.             "i:\p40tools\pdk\PiXCL41.exe,2",STRING,Res)
  166.  
  167.     RDBCreateKey(Handle,"Properties","",PXLPropHandle,Res)
  168.     RDBSetValue(PXLPropHandle,"Type1","256",DWORD,Res)
  169.  
  170.     RDBCreateKey(Handle,"Image Formats","",PXLImgHandle,Res)
  171.     RDBSetValue(PXLImgHandle,"Type2","BMP|RLE|PNG|JPG|",LIST,Res)
  172.  
  173.  
  174.  
  175.     If Res <= 1
  176.         DrawNumber(10,10,Handle)
  177.         DrawNumber(10,35,Res)
  178.     Else
  179.        DrawText(10,10,"Entry already exists")
  180.        DrawNumber(10,35,Handle)
  181.     Endif
  182.     
  183.     Goto Wait_for_Input 
  184.  
  185. Delete_Key:
  186.     DrawBackground
  187.     RDBDeleteKey(@RDB_CLASSES_ROOT,"PiXCL4.1",Res)
  188.     {RDBDeleteKey(Handle,"PiXCL4.1",Res)} {fails, key$ is not subkey of handle}
  189.     DrawNumber(10,10,Res)
  190.  
  191.     
  192.     Goto Wait_for_Input
  193.  
  194. Enum_Key:
  195.     DrawBackground
  196.     Index = 0
  197.     RDBEnumKey(Handle,0,SubKey$,Class$,Res)
  198.     DrawText(10,10,SubKey$)
  199.     If Class$ = "" Then Class$ = "Class$ returns NULL"
  200.     DrawText(10,30,Class$)
  201.  
  202.     RDBEnumKey(Handle,1,SubKey$,Class$,Res)
  203.     DrawText(10,50,SubKey$)
  204.     If Class$ = "" Then Class$ = "Class$ returns NULL"
  205.     DrawText(10,70,Class$)
  206.  
  207.     RDBEnumKey(Handle,2,SubKey$,Class$,Res)
  208.     DrawText(10,90,SubKey$)
  209.     If Class$ = "" Then Class$ = "Class$ returns NULL"
  210.     DrawText(10,110,Class$)
  211.  
  212.     {This should result in a "no more entries" Result=2}
  213.     RDBEnumKey(Handle,3,SubKey$,Class$,Res)
  214.     DrawNumber(230,150,Res)
  215.     If SubKey$ = "" Then SubKey$ = "SubKey$ returns NULL"
  216.     DrawText(25,130,SubKey$)
  217.     If Class$ = "" Then Class$ = "Class$ returns NULL"
  218.     DrawText(25,150,Class$)
  219.  
  220.  
  221.  
  222.     Goto Wait_for_Input
  223.  
  224. EnumLoop:
  225.     RDBEnumKey(Handle,Index,SubKey$,Class$,Res)
  226.     DrawBackGround    WaitInput(400)
  227.     DrawNumber(10,0,Res)
  228.     DrawText(10,20,SubKey$)
  229.     DrawText(10,40,Class$)
  230.     Index = Index + 1
  231.     If Res <> 2 Then Goto EnumLoop
  232.  
  233.  
  234.     Goto Wait_for_Input
  235.  
  236.  
  237. MAC_Address:
  238.     DrawBackground
  239.     Handle = 0
  240.          RDBOpenKey(@RDB_Local_Machine,
  241.     "SOFTWARE\Description\Microsoft\Rpc\UuidTemporaryData",Handle)
  242.     DrawNumber(10,10,Handle)
  243.         RDBQueryValue(Handle,"NetworkAddress",MACAddress$,Result)
  244.     DrawNumber(10,30,Result)  DrawText(25,30,MACAddress$)
  245.         RDBCloseKey(Handle,Result)
  246.     DrawNumber(10,50,Result)  
  247.  
  248.     Goto Wait_for_Input
  249.  
  250. {
  251.    I am trying to retrieve the Ethernet Hardware Address (MAC Address) from 
  252.      the Win 95 registry.  If you have an ethernet card, it is in the 
  253.      HKEY_LOCAL_MACHINE\SOFTWARE\Description\Microsoft\Rpc\UuidTemporaryData\
  254.      NetworkAddress key.  The value is 6 hexadecimal bytes long and is stored 
  255.      in what you call the "LIST token" format.  My MAC Address happens to be:
  256.      00 a0 24 c6 74 c9.  When I use the following piece of code,
  257.      
  258.      RDBOpenKey(@RDB_Local_Machine,"SOFTWARE\Description\Microsoft\Rpc\UuidTe
  259.      mporaryData",Handle)
  260.         RDBQueryValue(Handle,"NetworkAddress",MACAddress$,Result)
  261.         RDBCloseKey(Handle,Result)   
  262.      
  263.      MACAddress$ ends up equal to -24576.  What I really want is the 
  264.      MacAddress$ = "00 a0 24 c6 74 c9".  I have used the RDBSetValue to 
  265.      plug a value into the LIST format, but I have not used RDBQueryValue 
  266.      to retrieve a LIST formatted value (up to now, I have only queried 
  267.      string values).  What does -24576 represent?  ANSI numbers, maybe?  Do 
  268.      I need to use some form of ANSI and CHR to pull the hex values out?
  269.  
  270.  
  271. }
  272.  
  273.  
  274.  
  275.  
  276.  
  277.